package com.example.controller;

import com.example.entity.User;
import com.example.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author kangshuai
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/list")
    public List<User> list(@RequestParam String name) {
        User tbuser = new User();
        tbuser.setUsername(name);
        return userService.findByUser(tbuser);
    }

    @PostMapping("/save")
    public String save(@RequestBody User tbuser) {
        try {
            userService.save(tbuser);
            return "success";
        } catch (Exception e) {
            return "false";
        }
    }
}
